package com.baidu.sggc.entity;

public class UserContext {

    private static final ThreadLocal<LoginUserInfo> USER_HOLDER = new ThreadLocal<>();

    public static void setUser(LoginUserInfo user) {
        USER_HOLDER.set(user);
    }

    public static LoginUserInfo getUser() {
        return USER_HOLDER.get();
    }

    public static String getUserId() {
        LoginUserInfo user = USER_HOLDER.get();
        return user != null ? user.getUserId() : null;
    }

    public static String getUserName() {
        LoginUserInfo user = USER_HOLDER.get();
        return user != null ? user.getUserName() : null;
    }

    public static void clear() {
        USER_HOLDER.remove();
    }
}
